<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数组过滤</title>
</head>

<body>
  <select name="" id="">
    <option value="0">请选择销量范围</option>
    <option value="1">&lt100</option>
    <option value="2">100~500</option>
    <option value="3">&gt500</option>
  </select>
  <ul>
    <li>牛客logo马克杯</li>
    <li>无盖星空杯</li>
    <li>老式茶杯</li>
    <li>欧式印花杯</li>
  </ul>

  <script>
    var cups = [{
        type: 1,
        price: 100,
        color: 'black',
        sales: 60,
        name: '牛客logo马克杯'
      },
      {
        type: 2,
        price: 40,
        color: 'blue',
        sales: 100,
        name: '无盖星空杯'
      },
      {
        type: 4,
        price: 60,
        color: 'green',
        sales: 200,
        name: '老式茶杯'
      },
      {
        type: 3,
        price: 50,
        color: 'green',
        sales: 600,
        name: '欧式印花杯'
      }
    ]
    var select = document.querySelector('select');
    var ul = document.querySelector('ul');
    // 补全代码
    var cups = [{
        type: 1,
        price: 100,
        color: 'black',
        sales: 60,
        name: '牛客logo马克杯'
      },
      {
        type: 2,
        price: 40,
        color: 'blue',
        sales: 100,
        name: '无盖星空杯'
      },
      {
        type: 4,
        price: 60,
        color: 'green',
        sales: 200,
        name: '老式茶杯'
      },
      {
        type: 3,
        price: 50,
        color: 'green',
        sales: 600,
        name: '欧式印花杯'
      }
    ]
    var select = document.querySelector('select');
    var ul = document.querySelector('ul');
    // 补全代码
    select.onchange = function () {
      var index = select.selectedIndex;

      function show(arr) {
        let list = '';
        arr.forEach(function (v) {
          list += `<li>${v.name}</li>`
        })
        ul.innerHTML = list;
      }

      function choice(cups, index) {
        let resArr = cups.filter(function (v) {
          if (index == 1) {
            return v.sales < 100;
          } else if (index == 2) {
            return v.sales >= 100 && v.sales <= 500;
          } else if (index == 3) {
            return v.sales > 500;
          }
        })
        return resArr;
      }
      show(choice(cups, index));
    }
  </script>
</body>

</html>